﻿<template>
    <el-dialog :close-on-press-escape="false" :append-to-body="true" :visible="modalEdit" @opened="opened" :mask-closable="false" @closed="closed" @close="modalEdit=false">
        <el-form ref="saleOrder" label-position="right" label-width="120px" :model="saleOrder" :rules="rules">
            <input type="hidden" :model="saleOrder.id" />
            <el-form-item label="送货单号" prop="orderId">
                <el-input size="small" :readonly="saleOrder.id" v-model="saleOrder.orderId" placeholder="送货单号" style="width: 240px" />

                <span class="state-error">添加完不可修改</span>
            </el-form-item>
            <el-form-item label="类型" prop="type">
                <el-radio-group v-model="saleOrder.type">
                    <el-radio :label="1">送货单</el-radio>
                    <el-radio :label="2">生产条码</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="客户代码" prop="customerNo">
               
             <el-select size="small" :remote-method="getConsigneeIds"  remote :filterable="true" :loading="selectLoading" v-model="saleOrder.customerNo" placeholder="请输入客户代号/备注进行搜索" style="width: 280px">
                    <el-option v-for="(consignee,ind) in consignees" :value="consignee.customerCode" :key="consignee.customerCode" :label="consignee.customerCode+'-'+consignee.name">
                    </el-option>
                </el-select>
                <el-button size="small" :loading="selectLoading" icon="el-icon-search" circle @click="getConsigneeIds()"></el-button>
            </el-form-item>

        </el-form>
        <div slot="footer">
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" :loading="modalLoading" @click="ok">确定</el-button>
        </div>
    </el-dialog>
</template>
<script>
export default {
    name: 'SaleOrder',
    data() {
        return {
            selectLoading:false,
            modalEdit: false,
            modalLoading: false,
            saleOrderId: "",
            consignees:[],
            saleOrder: {
                type:1
            },
            rules: {

            }
        };
    },
    mounted: function() {


    },
    methods: {
        getConsigneeIds(val) {
            if (val == '' || val == undefined) {
                return;
            }
            this.selectLoading = true;
            this.$http.post("/sys/customer/getAll.action", { name: val })
                .then(response => {
                    this.selectLoading = false;
                    if (response.status == 0) {
                        this.consignees = response.obj;
                        // this.consigneeIDs = [];
                        // this.consignees.forEach((item) => {
                        //     this.consigneeIDs.push(item.consignee);
                        // });
                    } else {
                        this.errorMessage(response.info);
                    }
                }, response => {
                    this.selectLoading = false;
                })
        },
        opened() {

            this.getDetail();

        },
        closed() {
            this.saleOrder = {
                type:1
            }
        },
        showDialog(id) {
            this.saleOrderId = id;
            this.modalEdit = true;
        },
        getDetail: function() {
            if (this.saleOrderId == null || this.saleOrderId == undefined || this.saleOrderId == "") return;
            var me = this;
            me.showLoading();
            me.$http.get("/sys/saleorder/show_" + me.saleOrderId + ".action").then(response => {
                var body = response;
                if (body.status == 0) {
                    me.saleOrder = body.obj;

                }
                me.hideLoading();
            }, response => {
                me.hideLoading();
            });
        },
        ok: function() {
            var ok = false;
            this.$refs['saleOrder'].validate((valid) => {
                ok = valid;
                if (valid) {

                } else {
                    this.errorMessage('请认真填写数据');
                }
            })
            if (!ok) return;
            var me = this;

            me.modalLoading = true;
            me.$http.post("/sys/saleorder/doSave.action", me.saleOrder).then(response => {
               me.modalLoading = false;
                var body = response;
                if (body.status == 0) {
                    me.successMessage("保存成功！");
                    me.modalEdit = false;
                    me.$emit("ok");

                } else {
                    me.errorMessage(body.info);
                }
               
            }, response => {
                me.modalLoading = false;
            });
        },
        cancel: function() {
            this.saleOrder = {};
            this.modalEdit = false;
            this.$emit("cancel");
        }
    }
}
</script>
<style scoped>
</style>